using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace BassMati.Diagnostics 
{
	public class MainForm : System.Windows.Forms.Form
	{
		private System.ComponentModel.Container components = null;

		public MainForm ( )
		{
			InitializeComponent();
		}

		TestThread thread1, thread2;
		private System.Windows.Forms.MainMenu mainMenu;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem1;

		#region - Generated Code -

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.mainMenu = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			// 
			// mainMenu
			// 
			this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1,
																					 this.menuItem2,
																					 this.menuItem3,
																					 this.menuItem4,
																					 this.menuItem5});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "Create Threads";
			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "Listeners";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.Text = "&Trace";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 3;
			this.menuItem4.Text = "&Indent";
			this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 4;
			this.menuItem5.Text = "&Unindent";
			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(392, 273);
			this.Menu = this.mainMenu;
			this.Name = "MainForm";

		}
		#endregion

		[STAThread]
		static void Main() 
		{
			try { System.Diagnostics.Trace.WriteLine( "Program started." ); }
			catch ( Exception ex ) { System.Windows.Forms.MessageBox.Show( null, ex.Message, "ThreadListenerTest - Error", MessageBoxButtons.OK, MessageBoxIcon.Stop ); }
			Application.Run(new MainForm());
		}

		#endregion - Generated Code -

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			this.thread1 = new TestThread( "Thread-1", 1000 );
			this.thread2 = new TestThread( "Thread-2", 1800 );		
		}

		/// <summary>
		/// Writes a list of trace listeners.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			foreach ( System.Diagnostics.TraceListener listener in System.Diagnostics.Trace.Listeners )
			{
				System.Diagnostics.Debug.WriteLine( listener.Name );
			}
		}

		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Trace.WriteLine( "This is a test." );
		}

		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Trace.Indent();
		}

		private void menuItem5_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Trace.Unindent();
		}
	}
}
